package cn.wolfcode.wolfcodemall.service.impl;

import cn.wolfcode.wolfcodemall.domain.User;
import cn.wolfcode.wolfcodemall.mapper.UserMapper;
import cn.wolfcode.wolfcodemall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    public void save(User user) {
        userMapper.insert(user);
    }

    public User login(String username, String password) {
        User user = userMapper.login(username, password);
        if(user == null){
            throw new RuntimeException();
        }
        return user;
    }

    @Override
    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public List<User> selectAll(String name) {
        return userMapper.selectAll(name);
    }

    @Override
    public User selectByPrimaryKey(Integer user1) {

        return userMapper.selectByPrimaryKey(user1);
    }

    @Override
    public User selectByUserId(Integer user) {
        return userMapper.selectByUserId(user);
    }

}
